import util.ListNode;

/**
 * Created by loso on 2017/3/16.
 */
public class _141_LinkedListCycle {

    //重要 链表 循环 检测循环链表
    public boolean hasCycleBigBoss(ListNode head) {
        if(head==null) return false;
        ListNode walker = head;
        ListNode runner = head;
        while(runner.next!=null && runner.next.next!=null) {
            walker = walker.next;
            runner = runner.next.next;
            if(walker==runner) return true;
        }
        return false;
    }

    public boolean hasCycle(ListNode head) {
        if(head==null) return false;
        ListNode walker = head;
        ListNode runer = head;
        while(runer.next == null && runer.next.next != null){   //因为runer比walker快,
            walker = walker.next;
            runer = runer.next.next;
            if (walker == runer)
                return true;
        }
        return false;
    }
}
